package tk.djcrazy.instantmessage.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;

import tk.djcrazy.instantmessage.service.IFriendshipService;

import com.opensymphony.xwork2.ActionSupport;

public class FriendAction extends ActionSupport implements SessionAware {
 	private static final long serialVersionUID = -5663615577986612816L;
	private String friendName;
	private String nickName;
	private int groupId;
	private Map<String, Object> session;
	private String message;
	private String result="failed";

	@Resource
	private IFriendshipService  friendshipService;

	@Override
	public String execute() {
		return INPUT;
	}

	public String addFriend() {
		try {
			if (nickName!=null && nickName.trim()!="") {
	 			friendshipService.addFriendShipByName((Integer) session.get("uid"), friendName.trim(), nickName.trim(), groupId);
			} else {
	 			friendshipService.addFriendShipByName((Integer) session.get("uid"),
						friendName, groupId);
			}
			result="success";
			message = "成功添加好友：）";
		} catch (Exception e) {
			e.printStackTrace();
			result="failed";
			message = "未知错误";
		}
		return SUCCESS;
	}

	public String getFriendName() {
		return friendName;
	}

	public void setFriendName(String friendName) {
		this.friendName = friendName.trim();
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

 	public int getGroupId() {
		return groupId;
	}

	public void setGroupId(int groupId) {
		this.groupId = groupId;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public IFriendshipService getFriendshipService() {
		return friendshipService;
	}

	public void setFriendshipService(IFriendshipService friendshipService) {
		this.friendshipService = friendshipService;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName.trim();
	}

}